package cn.blue.base.service.impl;
import cn.blue.base.mapper.BaseMapper;
import cn.blue.base.query.BaseQuery;
import cn.blue.base.service.BaseService;
import cn.blue.base.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public void del(Long id) {
        baseMapper.del(id);

    }

    @Override
    public void add(T t) {
        baseMapper.add(t);

    }

    @Override
    public void update(T t) {
        baseMapper.update(t);

    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    public PageList queryByPage(BaseQuery query) {
        Integer totals = baseMapper.queryByCount(query);
        if (totals==null||totals==0){
            return new PageList<>(0,new ArrayList<>());
        }
        List<T> departmentPageList = baseMapper.queryByPage(query);
        return new PageList<>(totals,departmentPageList);

    }

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public void batchDel(List ids) {
        baseMapper.batchDel(ids );

    }
}
